package com.hehe.controller;
import com.hehe.Dao.Select_Mapper;
import com.hehe.Dao.Update_Mapper;
import com.hehe.POJO.Tb_sql_test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping(value="/index")
public class index2 {

    @Value("${spring.datasource.url}")
    private String age;

    @Autowired(required = false)
    private Select_Mapper select_mapper;

    @Autowired(required = false)
    private Update_Mapper update_mapper;

    @Autowired
    private JdbcTemplate jdbcTemplate;


    @GetMapping(value="")
    public String index(Model model, HttpServletRequest request, Integer id, String sql ){
        return "redirect:/index/all";
    }

    @GetMapping(value="/{type}")
    public String index_easy(Model model, HttpServletRequest request,  @PathVariable String type) {
        System.out.println("type = " + type);
        List<Tb_sql_test> sqlList = null;
        if (type.equals("all")){
            sqlList = select_mapper.get_all_sql_list();
        }
        assert sqlList != null;
        Integer all_counts = sqlList.size();
        model.addAttribute("sqlList" , sqlList);
        model.addAttribute("all_counts" , all_counts);
        return "index/index.html";
    }












//    @GetMapping(value="/aaa"  )
//    public String qqqqqq(Model model, HttpServletRequest request, Integer id, String sql ){
//        return "index/index.html";
//    }
//    @GetMapping(value="/bbb"  )
//    public String qqqvvv(Model model, HttpServletRequest request, Integer id, String sql ){
//        return "index/index.html";
//    }










}




